#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

static bool pandigital(int64_t num) {
    string s {to_string(num)};
    sort(s.begin(), s.end());
    return s == "123456789";
}

static bool pandigital_fibonacci_double() {
    static long double a = 1;
    static long double b = 1;
    long double c = a + b;
    while (c >= 1e9) {
        b /= 10;
        c /= 10;
    }
    a = b;
    b = c;
    return pandigital(static_cast<int64_t>(c));
}

static bool pandigital_fibonacci_integer() {
    static int64_t a = 1;
    static int64_t b = 1;
    int64_t c = a + b;
    b %= static_cast<int64_t>(1e9);
    c %= static_cast<int64_t>(1e9);
    a = b;
    b = c;
    return pandigital(c);
}

int main() {
    int64_t ans = 2;
    while (true) {
        ans++;
        bool bi = pandigital_fibonacci_integer();
        bool bd = pandigital_fibonacci_double();
        if (bi && bd) 
            break;
    }
    cout << ans << endl;
}   // 329468